﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EM.Repository.utility;
using System.Data.SqlClient;
using System.Data;

namespace EM.admin.SystemConfiguration
{
    public partial class _default : System.Web.UI.Page
    {
        public string APPROOT = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            int PageId = 22;
            Authentication ua = new Authentication();
            ua.CheckRolePageAuthentication(PageId, Authentication.RedirectionURLTypes.LoginPage);

            AppPathFinder AppPath = new AppPathFinder();
            APPROOT = AppPath.GetApplicationPath();

            if (!IsPostBack)
            {
                getData();
            }
        }

        void getData()
        {
            SqlCommand cmd = new SqlCommand();
            DbHelper dsrv = new DbHelper();
            string sSQL = @"SELECT GLOBALCODE,ISNULL(GLOBALVALUE,'') GLOBALVALUE,ISNULL(GLOBALDESC,'') GLOBALDESC
                            FROM TBLGLOBALDEFAULT           
                            WHERE VISIBLEFLG='Y'                            
                            ";
            cmd.CommandText = sSQL;
            DataTable dt = dsrv.GetDataTable(cmd, "");
            rptGlobalDefault.DataSource = dt;
            rptGlobalDefault.DataBind();
        }
        protected void rptGlobalDefault_ItemCommand(object sender, RepeaterItemEventArgs e)
        {


        }


        protected void rptGlobalDefault_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            DbHelper dsrv = new DbHelper();
            SqlCommand cmd = new SqlCommand();
            string sSQL = "";

            if (e.CommandName == "UPDATE")
            {
                TextBox txtGlobalValue = (TextBox)e.Item.FindControl("txtGlobalValue");
                sSQL = @"UPDATE TBLGLOBALDEFAULT SET GLOBALVALUE=@GLOBALVALUE
                             WHERE GLOBALCODE=@GLOBALCODE
                            ";
                cmd.Parameters.AddWithValue("@GLOBALVALUE", txtGlobalValue.Text);
                cmd.Parameters.AddWithValue("@GLOBALCODE", e.CommandArgument);
                cmd.CommandText = sSQL;
                dsrv.ExecuteNonQuery(cmd);
                getData();
            }

        }


    }
}